﻿/*
    This file is part of nDoctor Light

    NDoctor is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    NDoctor is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with NDoctor.  If not, see <http://www.gnu.org/licenses/>.
*/
namespace Probel.Ldoc.Test
{
    using System;
    using System.Collections.Generic;

    using NSubstitute;

    using NUnit.Framework;

    using Probel.Ldoc.Services.Dto;
    using Probel.Ldoc.Services.Services;
    using Probel.Ldoc.ViewModels.Helpers;
    using Probel.Ldoc.ViewModels.Pages;

    [TestFixture]
    public class TestPatientEditorViewModel
    {
        #region Methods

        [Test]
        public void ModifyData_AllNonCombobox_19PropertiesChanged()
        {
            var criterionFactory = Substitute.For<ICriterionFactory>();
            var errorService = Substitute.For<IErrorService>();
            var service = Substitute.For<IPatientService>();
            var patient = Substitute.For<PatientCardDto>();
            var counter = 0;

            service.Expand(Arg.Any<PatientCardDto>()).Returns(new ExpandedPatientDto());
            service.GetAllInsurances().Returns(new List<InsuranceCardDto>());
            service.GetAllReputations().Returns(new List<ReputationCardDto>());
            service.GetAllPractices().Returns(new List<PracticeCardDto>());
            service.GetAllProfessions().Returns(new List<ProfessionCardDto>());

            var vm = new PatientEditorViewModel(errorService, criterionFactory, service, patient);
            vm.PropertyChanged += (sender, e) => counter++;
            vm.Refresh();

            vm.Birthdate = DateTime.Today;
            vm.BoxNumber = string.Empty;
            vm.City = string.Empty;
            vm.Fee = 0;
            vm.FirstName = string.Empty;
            vm.InscriptionDate = DateTime.Today;
            vm.LastName = string.Empty;
            vm.LastUpdate = DateTime.Today;
            vm.PlaceOfBirth = string.Empty;
            vm.PostalCode = string.Empty;
            vm.PrivateMail = string.Empty;
            vm.PrivateMobile = string.Empty;
            vm.PrivatePhone = string.Empty;
            vm.ProMail = string.Empty;
            vm.ProMobile = string.Empty;
            vm.ProPhone = string.Empty;
            vm.Reason = string.Empty;
            vm.Street = string.Empty;
            vm.StreetNumber = string.Empty;
            vm.Thumbnail = new byte[] { 0, 0, 0, 0 };

            Assert.AreEqual(20, counter, "Not all properties are triggered");
        }

        [Test]
        public void ModifyData_WithNotInitialisedInstance_DefaultPatientIsCreated()
        {
            var criterionFactory = Substitute.For<ICriterionFactory>();
            var errorService = Substitute.For<IErrorService>();
            var service = Substitute.For<IPatientService>();
            var patient = Substitute.For<PatientCardDto>();
            var counter = 0;

            var vm = new PatientEditorViewModel(errorService, criterionFactory, service, patient);
            vm.PropertyChanged += (sender, e) => counter++;

            vm.Birthdate = DateTime.Today;
            vm.BoxNumber = string.Empty;
            vm.City = string.Empty;
            vm.Fee = 0;
            vm.FirstName = string.Empty;
            vm.InscriptionDate = DateTime.Today;
            vm.LastName = string.Empty;
            vm.LastUpdate = DateTime.Today;
            vm.PlaceOfBirth = string.Empty;
            vm.PostalCode = string.Empty;
            vm.PrivateMail = string.Empty;
            vm.PrivateMobile = string.Empty;
            vm.PrivatePhone = string.Empty;
            vm.ProMail = string.Empty;
            vm.ProMobile = string.Empty;
            vm.ProPhone = string.Empty;
            vm.Reason = string.Empty;
            vm.Street = string.Empty;
            vm.StreetNumber = string.Empty;
            vm.Thumbnail = new byte[] { 0, 0, 0, 0 };

            Assert.AreEqual(20, counter, "Not all properties are triggered");
        }

        #endregion Methods
    }
}